home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / DateSwitch / DateSwitch.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  5.6 KB  |  211 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import java.net.URLEncoder;
  12. import java.util.Calendar;
  13. import java.util.EventObject;
  14.  
  15. public class DateSwitch extends Applet implements ActionListener {
  16.    // $FF: renamed from: wi int
  17.    private int field_0;
  18.    // $FF: renamed from: he int
  19.    private int field_1;
  20.    private int mode = 0;
  21.  
  22.    public String getAppletInfo() {
  23.       return "Name: DateSwitch\r\nAuthor: Taiji Software\r\n";
  24.    }
  25.  
  26.    public void register() {
  27.       try {
  28.          URL u = new URL("http://www.taijisoftware.com");
  29.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  30.          ((Applet)this).stop();
  31.       } catch (Exception e) {
  32.          System.out.println(e);
  33.          ((Applet)this).stop();
  34.       }
  35.    }
  36.  
  37.    public void init() {
  38.       String codeBase = null;
  39.  
  40.       try {
  41.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  42.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  43.          codeBase = codeBase.toUpperCase();
  44.       } catch (Exception var9) {
  45.       }
  46.  
  47.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  48.          String regCode = ((Applet)this).getParameter("registration_code");
  49.          if (regCode == null) {
  50.             regCode = ((Applet)this).getParameter("reg_domain");
  51.             if (regCode == null) {
  52.                this.register();
  53.             } else {
  54.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  55.                   codeBase = "WWW." + codeBase;
  56.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  57.                   codeBase = codeBase.substring(4);
  58.                }
  59.  
  60.                char[] chars = new char[codeBase.length()];
  61.                codeBase.getChars(0, codeBase.length(), chars, 0);
  62.                String key = new String("haricot");
  63.                char[] chars2 = new char[key.length()];
  64.                key.getChars(0, key.length(), chars2, 0);
  65.  
  66.                for(int i = 0; i < codeBase.length(); ++i) {
  67.                   int j;
  68.                   if (i >= key.length()) {
  69.                      j = i - key.length() * (i / key.length());
  70.                   } else {
  71.                      j = i;
  72.                   }
  73.  
  74.                   chars[i] += chars2[j];
  75.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  76.                }
  77.  
  78.                String res = new String(chars);
  79.                if (!res.equalsIgnoreCase(regCode)) {
  80.                   this.register();
  81.                }
  82.             }
  83.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  84.             this.register();
  85.          }
  86.       }
  87.  
  88.       this.getParameters();
  89.       if (this.mode == 1) {
  90.          this.putComponents();
  91.       } else {
  92.          if (this.mode == 0) {
  93.             this.method_0();
  94.          }
  95.  
  96.       }
  97.    }
  98.  
  99.    public void getParameters() {
  100.       this.field_0 = ((Component)this).getSize().width;
  101.       this.field_1 = ((Component)this).getSize().height;
  102.       ((Component)this).setBackground(this.getColor("background_color"));
  103.       String s = ((Applet)this).getParameter("mode");
  104.       if (s != null) {
  105.          this.mode = Integer.parseInt(s);
  106.       }
  107.  
  108.    }
  109.  
  110.    public Color getColor(String param) {
  111.       String s = ((Applet)this).getParameter(param);
  112.       if (s != null) {
  113.          if (s.substring(0, 1).equals("#")) {
  114.             s = s.substring(1);
  115.             int i = Integer.parseInt(s, 16);
  116.             return new Color(i);
  117.          } else {
  118.             return null;
  119.          }
  120.       } else {
  121.          return null;
  122.       }
  123.    }
  124.  
  125.    // $FF: renamed from: go () void
  126.    public void method_0() {
  127.       Calendar cal = Calendar.getInstance();
  128.       int day = cal.get(6);
  129.       int n = 1;
  130.  
  131.       while(true) {
  132.          String s = ((Applet)this).getParameter("range" + Integer.toString(n));
  133.          if (s == null) {
  134.             this.method_1(((Applet)this).getParameter("no_range_link"));
  135.             return;
  136.          }
  137.  
  138.          int p = s.indexOf("#");
  139.          int min = Integer.parseInt(s.substring(0, p));
  140.          int max = Integer.parseInt(s.substring(p + 1));
  141.          if (day <= max && day >= min) {
  142.             this.method_1(((Applet)this).getParameter("link" + Integer.toString(n)));
  143.             return;
  144.          }
  145.  
  146.          ++n;
  147.       }
  148.    }
  149.  
  150.    // $FF: renamed from: go (java.lang.String) void
  151.    public void method_1(String link) {
  152.       if (link != null) {
  153.          try {
  154.             URL u = this.giveURL(link);
  155.             String target = ((Applet)this).getParameter("target");
  156.             if (target == null) {
  157.                target = "_self";
  158.             }
  159.  
  160.             ((Applet)this).getAppletContext().showDocument(u, target);
  161.          } catch (Exception err) {
  162.             System.err.println(err);
  163.          }
  164.       }
  165.    }
  166.  
  167.    public void putComponents() {
  168.       String s = ((Applet)this).getParameter("button_show_text");
  169.       if (s == null) {
  170.          s = "Enter !";
  171.       }
  172.  
  173.       Button showButton = new Button(s);
  174.       showButton.addActionListener(this);
  175.       ((Container)this).setLayout(new GridLayout(1, 1));
  176.       ((Container)this).add(showButton);
  177.    }
  178.  
  179.    public void actionPerformed(ActionEvent event) {
  180.       if (((EventObject)event).getSource() instanceof Button) {
  181.          this.method_0();
  182.       }
  183.    }
  184.  
  185.    public URL giveURL(String url) {
  186.       try {
  187.          if (url.toUpperCase().startsWith("HTTP")) {
  188.             return new URL(url);
  189.          } else if (url.toUpperCase().startsWith("FTP")) {
  190.             int p = url.indexOf(":");
  191.             int p2 = url.indexOf(":", p + 1);
  192.             if (p2 != -1) {
  193.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  194.             }
  195.  
  196.             p = url.indexOf("%40");
  197.             if (p != -1) {
  198.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  199.             }
  200.  
  201.             return new URL(url);
  202.          } else {
  203.             return new URL(((Applet)this).getCodeBase(), url);
  204.          }
  205.       } catch (MalformedURLException e) {
  206.          System.out.println(e);
  207.          return null;
  208.       }
  209.    }
  210. }
  211.